package com.incon.common.interceptor;
import java.io.IOException;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request,
            HttpServletResponse response, Authentication auth)
            throws IOException, ServletException {
    	      System.out.println( ((UserDetails) auth.getPrincipal()).getUsername());
    	      Random random = new Random();
    	       int s = random.nextInt(9999)%(9999-1000+1) + 1000;
    	      request.getSession().setAttribute("userId",  s);
              System.out.println(auth);
     }
}